<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title >小强博客</title>
    <link  rel="stylesheet" type="text/css" href="/Public/css/bootstrap.min.css" />
    <script type="text/javascript" src="/Public/js/jquery-3.1.1.js"></script>
    <script type="text/javascript" src="/Public/js/bootstrap.js"></script>
    <script type="text/javascript" src="/Public/js/layer.js"></script>
</head>
<style>
    .navbar-inverse{
   border-radius: inherit;
    }
    .navbar nav li:hover{
        background-color: white;
    }
</style>
<body>
<nav class="navbar navbar-inverse">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header ">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Blog v1.0</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="<?php if( CONTROLLER_NAME == 'Index' ): ?>active<?php endif; ?>"><a href="<?php echo U('Index/index');?>">
                <i class="glyphicon glyphicon-home">&nbsp;</i>首页  <span class="sr-only">(current)</span></a></li>
                <li  class="<?php if( CONTROLLER_NAME == 'Content' ): ?>active<?php endif; ?>"><a href="<?php echo U('Content/index');?>">内容</a></li>
                <li class="<?php if( CONTROLLER_NAME == 'Tools' ): ?>active<?php endif; ?>"><a href="<?php echo U('Tools/index');?>">功能</a></li>
                <li class="<?php if( CONTROLLER_NAME == '' ): ?>active<?php endif; ?>"><a href="#">用户</a></li>

            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/index.php"> 前台首页</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false"><span>您好 </span>&nbsp;<?php echo ($_SESSION['blog_admin']['name']); ?></a>
                    <ul class="dropdown-menu">
                        <li><a href="<?php echo U('Index/profile');?>">管理档案 </a></li>
                        <li><a href="<?php echo U('Index/quite');?>">注销 </a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
    <div class="container">
        <div class="row">
                    <div class="btn-group-vertical col-md-2">
        <a  class="btn btn-default  <?php if( CONTROLLER_NAME == 'Category' ): ?>active<?php endif; ?>" href="<?php echo U('Category/index');?>">
        <i class="glyphicon glyphicon-leaf">&nbsp;</i>分类管理 </a>
        <a  class="btn btn-default  <?php if( CONTROLLER_NAME == 'Tag' ): ?>active<?php endif; ?>" href="<?php echo U('Tag/index');?>" >
        <i class="glyphicon glyphicon-tags">&nbsp;</i>标签管理</a>
        <a  class="btn btn-default  <?php if( CONTROLLER_NAME == 'Article' ): ?>active<?php endif; ?>" href="<?php echo U('Article/index');?>" >
        <i class="glyphicon glyphicon-list-alt">&nbsp;</i>文章管理</a>

    </div>
            <div class="col-md-10">
                <div class="page-header"><h3> 管理分类</h3></div>
                        <div class="btn-group  role="group" aria-label="" style="padding-bottom:10px;" >
                        <a  class="btn btn-default" href="<?php echo U('Category/index');?>">所有分类</a>&nbsp;
                        <a  class="btn btn-default" href="<?php echo U('Category/add');?>"> 添加分类</a>

            </div>
                <div>
                    <table class="table table-bordered ">
                        <thead>
                            <tr class="active">
                                <td>id</td>
                                <td>排序</td>
                                <td> 类名称</td>
                                <td>状态</td>
                                <td>操作</td>
                            </tr>
                        </thead>
                        <tbody>
                        <?php if(is_array($categorys)): foreach($categorys as $key=>$c): ?><tr>
                                <td><?php echo ($c['id']); ?></td>
                                 <td><input type="text" value="<?php echo ($c['sort']); ?>" onchange="changeSort(this,<?php echo ($c['id']); ?>)"></td>
                                <td><?php if($c['pid'] != 0): echo str_repeat('&nbsp',$c['level']*8); endif; ?>|<?php echo ($c['cname']); ?></td>
                                   <td>
                                       <?php if($c['status']): ?><span class="label label-success">关闭</span>
                                           <?php else: ?>
                                           <span class="label label-danger">开启</span><?php endif; ?>
                                   </td>
                                   <td>
                                  <a class="btn btn-primary" href="<?php echo U('Category/edit',array('id'=>$c['id']));?>" >编辑</a>
                                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                  <a class="btn btn-danger" href="javascript:delCategory(<?php echo ($c['id']); ?>)">删除</a>
                                  </td>
                            </tr><?php endforeach; endif; ?>
                        </tbody>
                    </table>
                </div>
        </div>
        </div>
    </div>
<script>
    function changeSort(obj,id) {
        //alert(id);
        var csort = $(obj).val();
        $.ajax({
            'url': "<?php echo U('Category/changeSort');?>",
            'type': 'post',
            'dataType': 'json',
            'data': {'id':id, 'sort': csort},
            success:function(phpReturnData)
            {
                if (phpReturnData.status)
                {
                    layer.msg(phpReturnData.message, {'icon': 6}, function () {
                        window.location = location;
                    })
                }
            }
        })
    }
    function  delCategory(id) {
        layer.confirm(' 确认删除？', {
            btn: ['是','不'] //按钮
        }, function() {
            $.ajax({
                'url': "<?php echo U('Category/delete');?>",
                'type': 'POST',
                'dataType': 'json',
                'data': {'id': id},
                success: function (phpReturnData) {
                    //layer.msg(phpReturnData.message);
                    if (phpReturnData.status==1) {
                        layer.msg(phpReturnData.message, {'icon': 6}, function () {
                            window.location = location;
                        })
                    } else {
                        layer.msg(phpReturnData.message, {'icon': 5});
                    }
                }
            })
        })
    }
</Script>
</body>
</html>